package com.ruoyi.web.controller.books;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.books.domain.BooksMaterials;
import com.ruoyi.books.service.IBooksMaterialsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 非遗制作材料Controller
 *
 * @author ruoyi
 * @date 2024-03-28
 */
@Anonymous
@RestController
@RequestMapping("/books/materials")
public class BooksMaterialsController extends BaseController
{
    @Autowired
    private IBooksMaterialsService booksMaterialsService;

    /**
     * 查询非遗制作材料列表
     */
//    @PreAuthorize("@ss.hasPermi('books:materials:list')")
    @GetMapping("/list")
    public TableDataInfo list(BooksMaterials booksMaterials)
    {
        startPage();
        List<BooksMaterials> list = booksMaterialsService.selectBooksMaterialsList(booksMaterials);
        return getDataTable(list);
    }

    /**
     * 导出非遗制作材料列表
     */
//    @PreAuthorize("@ss.hasPermi('books:materials:export')")
    @Log(title = "非遗制作材料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BooksMaterials booksMaterials)
    {
        List<BooksMaterials> list = booksMaterialsService.selectBooksMaterialsList(booksMaterials);
        ExcelUtil<BooksMaterials> util = new ExcelUtil<BooksMaterials>(BooksMaterials.class);
        util.exportExcel(response, list, "非遗制作材料数据");
    }

    /**
     * 获取非遗制作材料详细信息
     */
//    @PreAuthorize("@ss.hasPermi('books:materials:query')")
    @GetMapping(value = "/{materialsId}")
    public AjaxResult getInfo(@PathVariable("materialsId") Long materialsId)
    {
        return success(booksMaterialsService.selectBooksMaterialsByMaterialsId(materialsId));
    }

    /**
     * 新增非遗制作材料
     */
//    @PreAuthorize("@ss.hasPermi('books:materials:add')")
    @Log(title = "非遗制作材料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BooksMaterials booksMaterials)
    {
        return toAjax(booksMaterialsService.insertBooksMaterials(booksMaterials));
    }

    /**
     * 修改非遗制作材料
     */
//    @PreAuthorize("@ss.hasPermi('books:materials:edit')")
    @Log(title = "非遗制作材料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BooksMaterials booksMaterials)
    {
        return toAjax(booksMaterialsService.updateBooksMaterials(booksMaterials));
    }

    /**
     * 删除非遗制作材料
     */
//    @PreAuthorize("@ss.hasPermi('books:materials:remove')")
    @Log(title = "非遗制作材料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{materialsIds}")
    public AjaxResult remove(@PathVariable Long[] materialsIds)
    {
        return toAjax(booksMaterialsService.deleteBooksMaterialsByMaterialsIds(materialsIds));
    }
}
